namespace Core.Features
{
    using System;
    using Base;
    using Contracts.Enums;
    using Resources;
    using System.Linq;

    
    public sealed class NexusModuleLockingTimeModification<T> : FeatureBase<object>
    {
        public NexusModuleLockingTimeModification(){}

        public NexusModuleLockingTimeModification(T value) 
            : base(value){ }

        /// <summary>
        /// Obtains the feature name
        /// </summary>
        public override string Name
        {
            get { return "Locking time"; }
        }

        /// <summary>
        /// Obtains the feature group
        /// </summary>
        public override FeatureGroupsEnum FeatureGroup { get { return FeatureGroupsEnum.Specific; } }
        /// <summary>
        /// Obtains the feature type
        /// </summary>
        public override FeaturesEnum FeatureType { get { return FeaturesEnum.NexusModuleLockingTimeModification; } }
        /// <summary>
        /// Obtains or defines the feature unit
        /// </summary>
        public override string Unit { get { return Traduction.label_unit_percent; } }

        public override string FormattedValue
        {
            get { return String.Format("{0} {1}", IsModified ? (double)ModifiedValue * 100 : (double)Value * 100, Unit); }
        }

        public override void SetModifiedValue(Contracts.Interfaces.IAgent agent, Contracts.Interfaces.IRobot robot)
        {
            if (agent == null || robot == null) return;

            double extensionBonus = agent.Extensions.Where(e => e.GetType() == typeof(Extensions.NexusAcceleratedTargetLocking))
                                                     .SumModifiersValues(FeatureTypesEnum.Module, this.FeatureType);

            double temp = (1 - Math.Abs((double)Value)) / (1 + extensionBonus);
            temp = (1 - temp) * (-1);

            ModifiedValue = IsRounded
                                ? Math.Round(temp, 0, MidpointRounding.AwayFromZero)
                                : Math.Round(temp, 2);
        }
    }
}